﻿using INTEX.DataBase;
using ReflectionStudio.Core.Events;
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.ComponentModel;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for SETUPABON.xaml
    /// </summary>
    public partial class TWFEVENTDEF
    {

        public TWFEVENTDEF()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VICC_WFEVENTDEF();
            this.DataContext = MV;
            InitializeComponent();
        } 
        public override void QueryCommand(object sender, RoutedEventArgs e)
        {

            try
            { 
                dwData = TBMain.NewRow();
                SResult = TMV.QueryICC_WFEVENTDEF(dwData, 9999);
                MergeData(SResult, true);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        public override void NewCommand(object sender, RoutedEventArgs e)
        {

            try
            {
                dwData = TBMain.NewRow();
                TMV.SetUpNewRow(ref dwData);
                TBMain.Rows.InsertAt(dwData, 0);
                vwMaster.View.MoveCurrentToFirst();
                TMV.InsertICC_WFEVENTDEF(dwData, app.company);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public override void CopyCommand(object sender, RoutedEventArgs e)
        {

            try
            {
                if (dwMaster == null)
                    return;
                dwData = TBMain.NewRow();
                dwData.ItemArray = dwMaster.ItemArray;
                dwData["ROWNID"] = INTEXDBC.GetSeq();
                TBMain.Rows.InsertAt(dwData, 0);
                vwMaster.View.MoveCurrentToFirst();
                TMV.InsertICC_WFEVENTDEF(dwData, app.company);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public override void EditCommand(object sender, RoutedEventArgs e)
        {
            try
            {

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);

            }
            finally
            {

            }
        }
        private void CopyAll_Click(object sender, RoutedEventArgs e)
        {
            try
            {

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);

            }

        }
       
        public override void SaveCommand(object sender, RoutedEventArgs e)
        {
            if (dwMaster == null)
                return;
            TMV.UpdateICC_WFEVENTDEF(dwMaster, app.company, 0);
        } 
        public override void DeleteCommand(object sender, RoutedEventArgs e)
        {
            if (dwMaster == null)
                return;
            TMV.DeleteICC_WFEVENTDEF(dwMaster, 1);

            filter = "ROWNID='" + dwMaster["ROWNID"].ToString() + "'";
            rows = TBMain.Select(filter);
            vwMaster.View.MoveCurrentTo(-1);
            foreach (DataRow row in rows)
            {
                row.Delete();
            }
            TBMain.AcceptChanges();
            base.DeleteCommand(sender, e);
        }

        private void Class_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBox cb = sender as ComboBox;
            dwMaster["WFCLASS"] = cb.SelectedValue;

        }

        private void Group_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBox cb = sender as ComboBox;
            dwMaster["WFTYPE"] = cb.SelectedValue;
        }

        private void Function_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBox cb = sender as ComboBox;
            dwMaster["WFEHANDLER"] = cb.SelectedValue;
        }
    }
}
